<?php
namespace Admin\Controller;
use Admin\Controller;
/**
 * 单页管理
 */
class HomepageController extends BaseController
{
    public function aboutUs(){
        $file = M('about_pho')->order('id desc')->limit(0,2)->select();
        foreach ($file as $v){
            $imgArr[] = $v;
        }
//        var_dump($imgArr);
        $this->assign('imgArr',$imgArr);

        $article = M('about_art')->order('id desc')->limit(0,1)->select();
        foreach ($article as $v){
            $artArr[] = $v;
        }
//        var_dump($artArr);
        $this->assign('artArr',$artArr);
        $this->display();
    }

    public function  aboutUs_upload(){
        if ($_POST['submit']=='更新图片'){
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 3145728 ;// 设置附件上传大小
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型

            // 上传文件01
            $info = $upload->upload();

            if(!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{// 上传成功
                if (!$info['photo1']||!$info['photo2']){
                    $this->error('不支持单张图片上传,请两张一起上传!');
                }
                $data = array(
                    '0' => array(
                        'filename' => $info['photo1']['savename'],
                        'fileurl' => $info['photo1']['savepath'],
                        'content' => $_POST['content1'],
                        'pid' => 1,
                    ),
                    '1' => array(
                        'filename' => $info['photo2']['savename'],
                        'fileurl' => $info['photo2']['savepath'],
                        'content' => $_POST['content2'],
                        'pid' => 2,
                    ),
                );
                if ($pd = M('about_pho')->addAll($data)){
                    $this->success('更新成功！');
                }
            }
        }

        if ($_POST['submit']=='更新文字'){
            $text = M('about_art');
            $photext = M('about_pho');
            $data = array(
                'content' => $_POST['content'],
            );
            $data2 = array(
                'content'=> $_POST['content1'],
            );
            $data3 = array(
                'content'=> $_POST['content2'],
            );
            $pd = $text->add($data);
            $where1['id'] = $_POST['hidden1'];
            $where2['id'] = $_POST['hidden2'];
            $pd1 = $photext->where($where1)->save($data2);
            $pd1 = $photext->where($where2)->save($data3);

            if($pd||$pd1||$pd2){
                $this->success('更新成功!');
            }
        }
    }

    public function chooseUs(){
        $file = M('choose_pho')->order('id desc')->limit(0,1)->select();
        foreach ($file as $v){
            $imgArr[] = $v;
        }
//        var_dump($imgArr);
        $this->assign('imgArr',$imgArr);
        $article = M('choose_art')->order('id desc')->limit(0,1)->select();
        foreach ($article as $v){
            $artArr[] = $v;
        }
//        var_dump($artArr);
        $this->assign('artArr',$artArr);
        $this->display();
    }

    public function chooseUs_upload(){
        if ($_POST['submit']=='更新图片'){
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 3145728 ;// 设置附件上传大小
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型

            // 上传文件01
            $info = $upload->upload();
            if(!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{// 上传成功
                $data = array(
                    'filename' => $info['photo']['savename'],
                    'fileurl' => $info['photo']['savepath'],
                    'pid' => 1,
                );
                if ($pd = M('choose_pho')->add($data)){
                    $this->success('上传成功！');
                }
            }
        }

        if ($_POST['submit']=='更新文字'){
            $text = M('choose_art');
            $data = array(
                'content' => $_POST['content'],
            );
                if($pd = $text->add($data)){
                    $this->success('更新成功!');
                }
        }

    }

    public function pro_dis(){
        $file = M('pro_dis_pho')->order('id desc')->limit(0,3)->select();
        foreach ($file as $v){
            $imgArr[] = $v;
        }
//        var_dump($imgArr);
        $this->assign('imgArr',$imgArr);

        $article = M('pro_dis_art')->order('id desc')->limit(0,1)->select();
        foreach ($article as $v){
            $artArr[] = $v;
        }
//        var_dump($artArr);
        $this->assign('artArr',$artArr);
        $this->display();
    }

    public function pro_dis_upload(){
        if ($_POST['submit']=='更新图片'){
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize = 3145728 ;// 设置附件上传大小
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型

            // 上传文件01
            $info = $upload->upload();

            if(!$info) {// 上传错误提示错误信息

                $this->error($upload->getError());
            }else{// 上传成功
                if (!$info['photo1']||!$info['photo2']||!$info['photo3']){
                    $this->error('不支持单张图片上传,请三张一起上传!');
                }
                $data = array(
                    '0' => array(
                        'filename' => $info['photo1']['savename'],
                        'fileurl' => $info['photo1']['savepath'],
                        'content' => $_POST['content1'],
                        'pid' => 1,
                    ),
                    '1' => array(
                        'filename' => $info['photo2']['savename'],
                        'fileurl' => $info['photo2']['savepath'],
                        'content' => $_POST['content2'],
                        'pid' => 2,
                    ),
                    '2' => array(
                        'filename' => $info['photo3']['savename'],
                        'fileurl' => $info['photo3']['savepath'],
                        'content' => $_POST['content2'],
                        'pid' => 3,
                    ),
                );
                if ($pd = M('pro_dis_pho')->addAll($data)){
                    $this->success('上传成功！');
                }
            }
        }
        if ($_POST['submit']=='更新文字'){
            $text = M('pro_dis_art');
            $data = array(
                'content' => $_POST['content'],
            );
                if($pd = $text->add($data)){
                    $this->success('更新成功!');
                }
        }
    }


}
?>